package com.jianshuge.app.bean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;

import com.jianshuge.app.AppException;
import com.jianshuge.app.common.StringUtils;

import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Xml;

/**
 * 通知信息实体类
 */
public class Notice implements Serializable {
	
	public final static String UTF8 = "UTF-8";
	public final static String NODE_ROOT = "jianshuge";
	
	public final static int	TYPE_ATME = 1;
	public final static int	TYPE_MESSAGE = 2;
	public final static int	TYPE_COMMENT = 3;
	public final static int	TYPE_NEWFAN = 4;

	private int atmeCount;
	private int msgCount;
	private int reviewCount;
	private int newFansCount;
	
	public int getAtmeCount() {
		return atmeCount;
	}
	public void setAtmeCount(int atmeCount) {
		this.atmeCount = atmeCount;
	}
	public int getMsgCount() {
		return msgCount;
	}
	public void setMsgCount(int msgCount) {
		this.msgCount = msgCount;
	}
	public int getReviewCount() {
		return reviewCount;
	}
	public void setReviewCount(int reviewCount) {
		this.reviewCount = reviewCount;
	}
	public int getNewFansCount() {
		return newFansCount;
	}
	public void setNewFansCount(int newFansCount) {
		this.newFansCount = newFansCount;
	}	
	
	public static Notice parse(InputStream inputStream) throws IOException, AppException {
		Notice notice = new Notice();
 
		String inputStr;
		BufferedReader streamReader = new BufferedReader( new InputStreamReader(inputStream) ); 
	    StringBuilder responseStrBuilder = new StringBuilder();
	    while ((inputStr = streamReader.readLine()) != null)
	        responseStrBuilder.append(inputStr);
	    String strResult = responseStrBuilder.toString();
	    
		try {
			JSONObject notice_json_obj = new JSONObject(strResult);	
			notice.setMsgCount( notice_json_obj.optInt("msgCount") );
			notice.setAtmeCount( notice_json_obj.optInt("atmeCount") );
			notice.setReviewCount( notice_json_obj.optInt("reviewCount") );
			notice.setNewFansCount( notice_json_obj.optInt("newFansCount") );
		} catch (JSONException e) { 	
            System.out.println("Jsons parse error !"); 
            e.printStackTrace(); 
		}
 		
        return notice;    
	}
}
